<?php include("include.php");?>
<?php
$jobid = $_GET['jid'];
$job = job::getJobById($jobid);
$quarks = quark::getQuarkByJobId($jobid);
?>
<h1>Welcome to Your Dashboard</h1>
<div id="contentTopBar">
	<div id="title">Job Statisics</div>
	<table>
    	<tr>
        	<td>Quarks Completed<br /><span id="main"><?php echo $job->getNumQuarkCompleted();?></span></td>
            <td id="other">Total Number of Quarks<br /><span><?php echo $job->getNumQuark();?></span></td>
            <td id="other">Quarks Not Started<br /><span><?php echo $job->getNumQuarkNotInProgress();?></span></td>
            <td id="other">Configure Quarks Solution<br />
            				<a href="configureJob.php?jid=<?php echo $jobid;?>"><img src="images/configure-icon.png"/></a>
                            </td>              
        </tr>
    </table>
</div>
<?php errorCheck()?>
<div id="contentPane">
<div id="tableTitle"><a href="addQuark.php?jid=<?php echo $jobid;?>" ><img src="images/add-icon.png" /></a>Quarks</div>
<div class="list">
<table>
<tr>
	<th>Quark ID</th>
    <th>Ressource Name</th>
    <th>Threshold</th>
    <th>Response Count</th>
    <th>Created</th>
    <th>Current State</th>
    <th>Preview</th>
    <th>Configure</th>
    <th>Delete</th>
</tr>
<?php
while($row = $quarks->fetch_assoc()){
	$tempQuark = new quark($row['id'],$row['job_id'],$row['ressource_link'],$row['threshold_count'],
				$row['feedback_count'],$row['solved'],$row['created_at'],$row['updated_at']);
	$tempSolution = quarkresolved::getQuarkResolvedByQuarkIdAndJobId($tempQuark->getId(),$jobid);
//go through every SQL row in the result set
	echo "<tr class=\"data\">";
		echo "<td>".$tempQuark->getId()."</td>";
		echo "<td>".$tempQuark->getRessourceLink()."</td>";
		echo "<td>".$tempQuark->getThresholdCount()."</td>";
		echo "<td>".$tempQuark->getResponseCount()."</td>";
		echo "<td>".date('D-F-Y',$tempQuark->getCreatedAt())." at ".date('h:i A',$tempQuark->getCreatedAt())."</td>";
		echo "<td>";
			if($tempSolution == NULL){
				echo "unsolved";
			}else{
				echo "solved";
			}
		echo "</td>";
		echo "<td><a href=\"quarkPreview.php?qid=".$tempQuark->getId().
				"&jid=".$tempQuark->getJob()->getId()."&refer=jobQuarks\">";
		echo "<img src=\"images/preview-icon.png\"></a></td>";
		echo "<td><a href=\"quarkConfigure.php?qid=".$tempQuark->getId().
				"\"><img src=\"images/setting-icon.png\"></a></td>";
		echo "<td><a href=\"deleteQuarkAction.php?jid=".$tempQuark->getJob()->getId()."&qid=".$tempQuark->getId()."\">".
				"<img src=\"images/delete-icon.png\"></a></td>";
	echo "</tr>\n";
	unset($tempQuark);
}
?>
</table>
</div>
</div>
<?php include("includes/footer.php");?>